<template>
    <div>
        <h1>编辑</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>name</td>
                    <td><input type="text" v-model="data.name"></td>
                </tr>
                <tr>
                    <td>loceng</td>
                    <td>
                    
                    <select v-model="data.loceng" >
                            
                            <option value="0">//请选择//</option>
                            <option value="一楼">一楼</option>
                            <option value="2楼">2楼</option>
                            <option value="3楼">3楼</option>
                            <option value="4楼">4楼</option>
                            <option value="5楼">5楼</option>
                        </select></td>
                </tr>
                <tr>
                    <td>Phone</td>
                    <td><input type="text" v-model="data.Phone"></td>
                </tr>
                <tr>
                    <td>mianj</td>
                    <td><input type="text" v-model="data.mianj"></td>
                </tr>
                <tr>
                    <td>Tid</td>
                    <td>
                        <select v-model="data.Tid" >
                            
                            <option value="0">//请选择//</option>
                            <option v-for="d in xia" :value="d.Tid">{{ d.Ttype }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><input type="button" value="编辑" class="btn btn-success" @click="bianj"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router';
const routr =  useRoute();
onMounted(() => {
    xiala();
    fant();
});


const data = ref(
   [ {
    "name": "",
    "loceng": "",
    "mianj": "",
    "Phone": "",
    "Tid": 0,
  }]
)
const fant = ()=>{
    var mid = routr.query.id
    alert(mid);
    axios.get("https://localhost:7048/api/Base/FTone",{params:{id:mid}}).then(res=>{
        data.value=res.data
    })
}

const bianj = ()=>{
    if(data.value.name=="")
    {
        alert("名称不能为空!");
        return;
    }
if(data.value.loceng==0)
    {
        alert("楼层不能为空!");
        return;
    }
    if(data.value.Phone=="")
    {
        alert("手机号不能为空!");
        return;
    }
    if(data.value.Phone==185825)
    {
        alert("手机号不能一样!");
        return;
    }
    if(data.value.Phone==1)
    {
        alert("请输入正确的手机号格式!");
        return;
    }
    if(data.value.Phone==12)
    {
        alert("请输入正确的手机号格式!");
        return;
    }
    if(data.value.mianj=="")
    {
        alert("面积不能为空!");
        return;
    }
    if(data.value.Tid==0)
    {
        alert("请选择房间状态!");
        return;
    }

    axios.post("https://localhost:7048/api/Base/Uptone",data.value).then(res=>{
        if(res.data>=1)
        {
            alert("编辑成功");
            location.href='/';
        }
        else
        {
            alert("编辑失败");
        }
    })
}



const xia=ref([
    {
    "Tid": 0,
    "Ttype": ""
  }
])
const xiala = ()=>{
    axios.get("https://localhost:7048/api/Base/ShowTwo").then(res=>{
        xia.value=res.data
    })
}
</script>

<style scoped>

</style>